package interview;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Demo22 {
    public static void main1(String[] args) {
        String s = "abcabcd";
        System.out.println(s.replace('a', 'c'));
        System.out.println(s);
    }

    public static void main(String[] args) throws InterruptedException {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(2, 4, 5,
                TimeUnit.SECONDS, new ArrayBlockingQueue<>(2));
        for (int i = 0; i < 10; i++) {
            int tmp = i;
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    if(tmp % 2 == 0 && tmp > 2){
                        throw new RuntimeException();
                    }
                    System.out.println(tmp + Thread.currentThread().getName() + " 在执行任务");
                }

            });
//            boolean b = executor.awaitTermination(1, TimeUnit.SECONDS);
//            System.out.println(b);
        }
    }
}
